/*     */ package com.wgcloud.controller;
/*     */ 
/*     */ import cn.hutool.json.JSONObject;
/*     */ import cn.hutool.json.JSONUtil;
/*     */ import com.wgcloud.entity.DeskIo;
/*     */ import com.wgcloud.entity.DeskState;
/*     */ import com.wgcloud.entity.DiskSmart;
/*     */ import com.wgcloud.entity.FileSafe;
/*     */ import com.wgcloud.service.AppInfoService;
/*     */ import com.wgcloud.service.DockerInfoService;
/*     */ import com.wgcloud.service.FileSafeService;
/*     */ import com.wgcloud.util.DateUtil;
/*     */ import com.wgcloud.util.FormatUtil;
/*     */ import com.wgcloud.util.ThreadPoolUtil;
/*     */ import com.wgcloud.util.TokenUtils;
/*     */ import com.wgcloud.util.msg.WarnMailUtil;
/*     */ import com.wgcloud.util.staticvar.BatchData;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.web.bind.annotation.RequestBody;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/agentDiskGo"})
/*     */ public class AgentDiskController
/*     */ {
/*  45 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.AgentDiskController.class);
/*     */ 
/*     */   
/*     */   @Autowired
/*     */   DockerInfoService dockerInfoService;
/*     */ 
/*     */   
/*     */   @Autowired
/*     */   AppInfoService appInfoService;
/*     */ 
/*     */   
/*     */   @Autowired
/*     */   FileSafeService fileSafeService;
/*     */   
/*     */   @Autowired
/*     */   private TokenUtils tokenUtils;
/*     */ 
/*     */   
/*     */   @ResponseBody
/*     */   @RequestMapping({"/minTask"})
/*     */   public JSONObject minTask(@RequestBody String paramBean) {
/*  66 */     JSONObject agentJsonObject = (JSONObject)JSONUtil.parse(paramBean);
/*  67 */     logger.debug("agent上报磁盘数据-------------" + agentJsonObject.toString());
/*  68 */     JSONObject resultJson = new JSONObject();
/*  69 */     if (!this.tokenUtils.checkAgentToken(agentJsonObject)) {
/*  70 */       logger.error("token is error");
/*  71 */       resultJson.set("result", "token is error");
/*  72 */       return resultJson;
/*     */     } 
/*     */     
/*  75 */     String bindIp = agentJsonObject.getStr("bindIp");
/*  76 */     if (isExists(bindIp)) {
/*  77 */       logger.error("agentDisk multiple times at the same time：" + bindIp);
/*  78 */       resultJson.set("result", "agentDisk multiple times at the same time：" + bindIp);
/*  79 */       return resultJson;
/*     */     } 
/*     */     
/*  82 */     JSONObject diskInfoListJson = agentJsonObject.getJSONObject("diskInfoList");
/*     */     
/*  84 */     JSONObject diskIoJson = agentJsonObject.getJSONObject("diskIo");
/*     */     
/*  86 */     JSONObject diskSmartJson = agentJsonObject.getJSONObject("diskSmart");
/*     */     
/*  88 */     JSONObject fileSafesJson = agentJsonObject.getJSONObject("fileSafes");
/*  89 */     String hostName = agentJsonObject.getStr("hostName");
/*     */     
/*  91 */     Date nowtime = DateUtil.getNowTime();
/*     */     
/*  93 */     if (StringUtils.isEmpty(bindIp)) {
/*  94 */       bindIp = hostName;
/*  95 */       logger.error("bindIp is null");
/*  96 */       if (StringUtils.isEmpty(bindIp)) {
/*  97 */         resultJson.set("result", "error：bindIp is null");
/*  98 */         return resultJson;
/*     */       } 
/*     */     } 
/*     */ 
/*     */ 
/*     */ 
/*     */     
/* 105 */     try { if (diskInfoListJson != null) {
/* 106 */         addDeskState(diskInfoListJson, nowtime, bindIp);
/*     */       }
/*     */       
/* 109 */       if (diskIoJson != null) {
/* 110 */         addDeskIo(diskIoJson, nowtime, bindIp);
/*     */       }
/*     */ 
/*     */       
/* 114 */       if (diskSmartJson != null) {
/* 115 */         addDiskSmart(diskSmartJson, nowtime, bindIp);
/*     */       }
/*     */ 
/*     */       
/* 119 */       if (fileSafesJson != null) {
/* 120 */         addFileSafes(fileSafesJson, nowtime, bindIp);
/*     */       }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */       
/* 128 */       return resultJson; } catch (Exception e) { logger.error("解析磁盘上报数据错误", e); return resultJson; } finally { Exception exception = null; }
/*     */   
/*     */   }
/*     */ 
/*     */   
/*     */   private void addDeskState(JSONObject diskInfoListJson, Date nowtime, String bindIp) {
/*     */     try {
/* 135 */       List<String> keys = new ArrayList<>(diskInfoListJson.keySet());
/* 136 */       for (String diskname : keys) {
/* 137 */         JSONObject diskJson = diskInfoListJson.getJSONObject(diskname);
/* 138 */         DeskState bean = new DeskState();
/* 139 */         bean.setFileSystem(diskname);
/* 140 */         bean.setHostname(bindIp);
/* 141 */         bean.setCreateTime(nowtime);
/* 142 */         bean.setUsed(FormatUtil.formatDouble(Double.valueOf(diskJson.getLong("used").longValue() / 1024.0D / 1024.0D / 1024.0D), 2) + "G");
/* 143 */         bean.setAvail(FormatUtil.formatDouble(Double.valueOf(diskJson.getLong("free").longValue() / 1024.0D / 1024.0D / 1024.0D), 2) + "G");
/* 144 */         bean.setSize(FormatUtil.formatDouble(Double.valueOf(diskJson.getLong("total").longValue() / 1024.0D / 1024.0D / 1024.0D), 2) + "G");
/* 145 */         bean.setUsePer(FormatUtil.formatDouble(diskJson.getDouble("usedPercent"), 2) + "%");
/* 146 */         BatchData.DESK_STATE_LIST.add(bean);
/* 147 */         Runnable runnable = () -> WarnMailUtil.sendDiskWarnInfo(bean);
/*     */ 
/*     */         
/* 150 */         ThreadPoolUtil.executor.execute(runnable);
/*     */       } 
/* 152 */     } catch (Exception e) {
/* 153 */       logger.error("解析磁盘上报数据错误", e);
/*     */     } 
/*     */   }
/*     */   
/*     */   private void addDeskIo(JSONObject diskIoListJson, Date nowtime, String bindIp) {
/*     */     try {
/* 159 */       List<String> keys = new ArrayList<>(diskIoListJson.keySet());
/* 160 */       for (String diskname : keys) {
/* 161 */         DeskIo ioBean = new DeskIo();
/* 162 */         JSONObject deskIoJsonObj = diskIoListJson.getJSONObject(diskname);
/* 163 */         if (null != deskIoJsonObj) {
/* 164 */           ioBean.setFileSystem(diskname);
/* 165 */           ioBean.setHostname(bindIp);
/* 166 */           ioBean.setCreateTime(nowtime);
/* 167 */           ioBean.setReadCount(deskIoJsonObj.getLong("readCount") + "");
/* 168 */           ioBean.setWriteCount(deskIoJsonObj.getLong("writeCount") + "");
/* 169 */           ioBean.setReadBytes((deskIoJsonObj.getLong("readBytes").longValue() / 1024L / 1024L / 1024L) + "G");
/* 170 */           ioBean.setWriteBytes((deskIoJsonObj.getLong("writeBytes").longValue() / 1024L / 1024L / 1024L) + "G");
/* 171 */           ioBean.setReadTime(deskIoJsonObj.getLong("readTime") + "");
/* 172 */           ioBean.setWriteTime(deskIoJsonObj.getLong("writeTime") + "");
/* 173 */           BatchData.DESK_IO_LIST.add(ioBean);
/*     */         } 
/*     */       } 
/* 176 */     } catch (Exception e) {
/* 177 */       logger.error("解析磁盘IO数据错误", e);
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/*     */   private void addDiskSmart(JSONObject diskSmartListJson, Date nowtime, String bindIp) {
/*     */     try {
/* 184 */       List<String> keys = new ArrayList<>(diskSmartListJson.keySet());
/* 185 */       for (String diskname : keys) {
/* 186 */         DiskSmart smartBean = new DiskSmart();
/* 187 */         smartBean.setFileSystem(diskname);
/* 188 */         smartBean.setHostname(bindIp);
/* 189 */         smartBean.setCreateTime(nowtime);
/* 190 */         smartBean.setDiskState(diskSmartListJson.getStr(diskname));
/* 191 */         BatchData.DISK_SMART_LIST.add(smartBean);
/*     */       } 
/* 193 */     } catch (Exception e) {
/* 194 */       logger.error("解析磁盘smart数据错误", e);
/*     */     } 
/*     */   }
/*     */   
/*     */   private void addFileSafes(JSONObject fileSafeJson, Date nowtime, String bindIp) {
/*     */     try {
/* 200 */       List<String> keys = new ArrayList<>(fileSafeJson.keySet());
/* 201 */       for (String fileSafeId : keys) {
/* 202 */         String state = fileSafeJson.getStr(fileSafeId);
/* 203 */         FileSafe fileSafe = new FileSafe();
/* 204 */         fileSafe.setId(fileSafeId);
/* 205 */         fileSafe.setCreateTime(nowtime);
/* 206 */         fileSafe.setState(state);
/* 207 */         fileSafe.setHostname(bindIp);
/*     */ 
/*     */         
/* 210 */         if (!"1".equals(state)) {
/* 211 */           fileSafe.setState("2");
/* 212 */           BatchData.FILE_SAFE_LIST.add(fileSafe);
/* 213 */           Runnable runnable = () -> {
/*     */               try {
/*     */                 FileSafe portInfoW = this.fileSafeService.selectById(fileSafeId);
/*     */                 if (portInfoW != null) {
/*     */                   WarnMailUtil.sendFileSafeDown(portInfoW, true);
/*     */                 }
/* 219 */               } catch (Exception e) {
/*     */                 e.printStackTrace();
/*     */               } 
/*     */             };
/*     */           
/* 224 */           ThreadPoolUtil.executor.execute(runnable);
/*     */           
/*     */           continue;
/*     */         } 
/* 228 */         BatchData.FILE_SAFE_LIST.add(fileSafe);
/*     */       } 
/* 230 */     } catch (Exception e) {
/* 231 */       logger.error("解析文件防篡改监测信息上报数据错误", e);
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private boolean isExists(String bindIp) {
/* 242 */     if (StringUtils.isEmpty(bindIp)) {
/* 243 */       return true;
/*     */     }
/* 245 */     for (DeskState deskState : BatchData.DESK_STATE_LIST) {
/* 246 */       if (deskState.getHostname().equals(bindIp)) {
/* 247 */         return true;
/*     */       }
/*     */     } 
/* 250 */     for (DeskIo deskIo : BatchData.DESK_IO_LIST) {
/* 251 */       if (deskIo.getHostname().equals(bindIp)) {
/* 252 */         return true;
/*     */       }
/*     */     } 
/* 255 */     for (DiskSmart diskSmart : BatchData.DISK_SMART_LIST) {
/* 256 */       if (diskSmart.getHostname().equals(bindIp)) {
/* 257 */         return true;
/*     */       }
/*     */     } 
/* 260 */     return false;
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/AgentDiskController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */